# -*- coding: utf-8 -*-
# @Time : 2025/1/25 11:31
# @Author : debbyszhang
# @File : gateway_info.py
# @desc :


import re

import allure
from playwright.sync_api import Playwright, sync_playwright, expect

from pageObject.cross_gateway_list_page import CrossGatewayListPage


@allure.feature("跨链网关信息")
class TestGatewayInfo:

    def test_gateway_info(self, page):
        cross_gateway_page = CrossGatewayListPage(page)

        gateway_name = 'tcip-chainmaker20250125140027'
        cross_gateway_page.click(gateway_name)
        text = page.get_by_text(gateway_name).nth(1)

        # text = cross_gateway_page.get_text(gateway_name)
        # print(text.text_content())

        # 查找所有的表单项
        items = page.locator(".tea-form__item").all()

        # 遍历每个表单项
        for item in items:
            label = item.locator(".tea-form__label").text_content()
            text = item.locator(".tea-form__text").text_content()
            print(label + ":" + text)
            # 获取label文本
            # 检查label文本是否为“跨链网关名称”
            if label == "跨链网关名称":
                # 获取对应的tea-form__text内容
                text = item.locator(".tea-form__text").text_content()
                print(text)

        # # 获取创建时间标签
        # creation_time_label = page.locator("div.tea-form_label:has-text('创建时间')")
        # # 获取创建时间标签后面的值
        # creation_time = creation_time_label.locator("+ div.tea-form_text").text_content()
        # print(f"创建时间: {creation_time}")
        #
        # # 获取跨链网关名称标签
        # gateway_name_label = page.locator("div.tea-form_label:has-text('跨链网关名称')")
        # # 获取跨链网关名称标签后面的值
        # gateway_name = gateway_name_label.locator("+ div.tea-form_text").text_content()
        # print(f"跨链网关名称: {gateway_name}")

        # expect(cross_gateway_page.get_text("tcip-fabric20250116143212").nth(1)).to_be_visible())
        # expect(page.get_by_text("tcip-fabric20250116143212").nth(1)).to_be_visible()
        # page.get_by_text("接入申请").click()
        # expect(page.get_by_text("申请通过")).to_be_visible()
        # expect(page.locator("tbody")).to_contain_text("tcip-fabric20250116143212")
        # page.get_by_title("tcip-fabric20250116143212").click()
        # expect(page.get_by_title("tcip-fabric20250116143212")).to_be_visible()
        # page.get_by_text("子链信息").click()
        # page.get_by_text("fabric20250116143214").click()
        # page.get_by_text("事件配置信息").click()

        # name = 'tcip-chainmaker20250125140027'
        # t = cross_gateway_page.gateway_info(name)
        # expect(t.locator("tbody")).to_contain_text(name)
        # assert t == '新增成功'

# def run(playwright: Playwright) -> None:
#     browser = playwright.chromium.launch(headless=False)
#     context = browser.new_context()
#     page = context.new_page()
#     page.goto("http://192.168.0.173:8088/login")
#     page.get_by_placeholder("请输入用户名").click()
#     page.get_by_placeholder("请输入用户名").fill("cross")
#     page.get_by_placeholder("请输入密码").click()
#     page.get_by_placeholder("请输入密码").fill("abcd1234")
#     page.get_by_role("button", name="登录").click()
#     page.get_by_role("link", name="跨链网关").click()
#     page.get_by_role("cell", name="tcip-ant20250121111332").locator("div").click()
#     page.get_by_text("接入申请").click()
#     page.get_by_text("子链信息").click()
#     page.get_by_text("事件配置信息").click()
#     page.get_by_role("button", name="详情").click()
#
#     # ---------------------
#     context.close()
#     browser.close()
#
#
# with sync_playwright() as playwright:
#     run(playwright)
